package cn.wf.order.message;

import cn.wf.order.dto.OrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.SendTo;

/**
 * @Description
 * @Author 万飞
 * @Date 2018/8/12 2:24
 */
@EnableBinding(StreamClient.class)
@Slf4j
public class StreamReceiver {

//    @StreamListener(value = StreamClient.INPUT)
//    public void process(Object message) {
//        log.info("StreamReceiver: {}", message);
//    }

    /**
     * 接收 orderDTO对象
     * @param message
     */
    @StreamListener(value = StreamClient.INPUT)
    @SendTo(StreamClient.INPUT2)  //返回消息，会被下面方法接收
    public String processOrderDTO(OrderDTO message) {
        log.info("【发送消息接收】StreamReceiver orderDTO: {}", message);
        return "received.";
    }

    @StreamListener(value = StreamClient.INPUT2)
    public void processReceived(String message) {
        log.info("【发送消息接收返回】StreamReceived :{}", message);
    }
}
